package com.leetcode.studyplan.algorithm.basis;

public class L_153_FindMinimumInRotatedSortedArray {

    public static void main(String[] args) {
        L_153_FindMinimumInRotatedSortedArray array = new L_153_FindMinimumInRotatedSortedArray();
        int[] nums = {3,4,5,1,2};
//        int[] nums = {4,5,6,7,0,1,2};
//        int[] nums = {11,13,15,17};
//        int[] nums = {2,3,4,5,6,1};
        System.out.println(array.findMin(nums));
    }

    public int findMin(int[] nums) {

        int left = 0;
        int right = nums.length - 1;
        int res = Integer.MAX_VALUE;
        while (left <= right) {

            int mid = (left + right) / 2;
            if (nums[mid] < nums[right]) {
                if (nums[mid] < res) {
                    res = nums[mid];
                }
                right = mid - 1;
            } else {
                if (nums[left] < res) {
                    res = nums[left];
                }
                left = mid + 1;
            }
        }
        return res;
    }

}
